/*
 * SocketClientTest.cpp
 */

#include "SocketClientTest.h"
#include "../../log/Log.h"
#include "../../sockets/ByteBuffer.h"

SocketClientTest::SocketClientTest(bool detailedMode) {
	this->detailedMode = detailedMode;
}

SocketClientTest::~SocketClientTest() {
}

void SocketClientTest::run() {
	try {
		// Me conecto al server
		cs.doConnect("127.0.0.1", "4000");

		// Envio algo
		std::string msg("mi primer mensaje...");
		if (detailedMode) Log::getInstance()->info("[CLIENT] Envio cadena: " + msg);
		cs.doSend(msg.data(), msg.size());
		if (detailedMode) Log::getInstance()->info("[CLIENT] Cadena enviada");

		// Recibo algo completo
		ByteBuffer bf;
		cs.doReceiveComplete(&bf);
		if (detailedMode) Log::getInstance()->info("[CLIENT] Recibi:" + bf.getAll());

		cs.doClose();
	} catch (...) {
		Log::getInstance()->error("error en ClienetTest..");
	}
}
